package com.easy.work.function.main.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.easy.work.R;
import com.easy.work.bean.CompanyBriefBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author zhangfeng
 * @date 2018/01/12
 * @desc
 */

public class CompanyBriefAdapter extends ArrayAdapter<CompanyBriefBean.WorkBaseListEntity> {

    private List<CompanyBriefBean.WorkBaseListEntity> mList;
    private LayoutInflater mInflater;

    public CompanyBriefAdapter(Context context, int resource, List<CompanyBriefBean.WorkBaseListEntity> objects) {
        super(context, resource, objects);
        mList = objects;
        mInflater = LayoutInflater.from(context);
    }

    public void refreshData(List<CompanyBriefBean.WorkBaseListEntity> list) {
        mList.clear();
        addMoreData(list);
    }

    public void addMoreData(List<CompanyBriefBean.WorkBaseListEntity> list) {
        mList.addAll(list);
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_company_brief, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        CompanyBriefBean.WorkBaseListEntity entity = mList.get(position);
        holder.tvName.setText(entity.title);
        holder.tvSalary.setText(entity.salaryFrom + "-" + entity.salaryTo + "元/月");

        return convertView;
    }

    class ViewHolder {

        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.tv_salary)
        TextView tvSalary;

        ViewHolder(View v) {
            ButterKnife.bind(this, v);
        }
    }
}
